package com.dk.mq;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dk.pojo.TSpike;
import com.dk.pojo.TSpikeOrder;
import com.dk.service.ITSpikeOrderService;
import com.dk.service.ITSpikeService;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import util.IdWorker;

@RocketMQMessageListener(consumerGroup = "mygroup",topic = "seckill")
@Component
public class TSpikeOrderMQ implements RocketMQListener<TSpikeOrder> {

    @Autowired
    private ITSpikeOrderService orderService;

    //修改秒杀订单状态
    @Override
    public void onMessage(TSpikeOrder order) {
        QueryWrapper wrapper = new QueryWrapper<TSpikeOrder>();
        wrapper.eq("admin_id",order.getAdminId());
        wrapper.eq("seckill_id",order.getSeckillId());
        TSpikeOrder spikeOrder = orderService.getOne(wrapper);
        if ("1".equals(spikeOrder.getStatus())){
            orderService.remove(wrapper);
        }
    }
}
